import dis
import threading

#lock = threading.Lock()
lock = threading.RLock()  #可重入锁, 同一个线程里可以多次锁，只要保证 acquire release 一一匹配
a = 0
def add():
    global a
    global lock
    for i in range(100000):
        lock.acquire()
        lock.acquire()
        a += 1
        lock.release()
        lock.release()

def desc():
    global a
    global lock
    for i in range(100000):
        lock.acquire()
        a -= 1
        lock.release()


if __name__ == '__main__':
    t1 = threading.Thread(target=add)
    t2 = threading.Thread(target=desc)
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    print(a)
